<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
		<link rel="stylesheet" href="__CSS__/admin.css" media="all">
	</head>
    <style>
    	.layui-word-aux{
    		color: #2BB6F6!important;
    		cursor:pointer;
    	}
    </style>
	<body style="padding:10px;">
		<div class="tplay-body-div">
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li>
						<a href="{:url('admin/member/memlist')}" class="a_menu">会员列表</a>
					</li>
					<li class="layui-this">编辑会员信息</li>
				</ul>
			</div>
			<form class="layui-form" id="mem">

				<div class="layui-form-item">
					<label class="layui-form-label">会员级别</label>
					<div class="layui-input-inline">
						<select name="level_id" lay-filter="aihao">
							 {volist name="$level" id="v"} 
							<option value="{$v.id}" {if condition="$info.level_id eq $v.id" }selected{/if}>{$v.name}</option>
							{/volist}
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">会员卡号</label>
					<div class="layui-input-inline">
						<input name="card" value="{$info.card}" placeholder="请输入会员卡号" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">会员名称</label>
					<div class="layui-input-inline">
						<input name="user_name" value="{$info.user_name}" placeholder="请输入会员姓名" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">会员电话</label>
					<div class="layui-input-inline">
						<input name="mobile" id="mobile" value="{$info.mobile}" placeholder="请输入会员电话" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">密码</label>
					<div class="layui-input-inline">
						<input name="password" id="password" placeholder="请输入密码" autocomplete="off" class="layui-input" type="text" maxlength="12">
					</div> 
					<div class="layui-form-mid" style="color: #999;">请填写6到12位密码</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">房券</label>
					<div class="layui-input-inline">
						<input name="kaquan" value="{$info.kaquan}" autocomplete="off" class="layui-input" type="text" disabled>
					</div>
					<div class="layui-form-mid layui-word-aux" onclick="faedit('{$info.id}')">修改</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="sex" value="1" title="男" {if $info['sex']==1 }checked{/if}>
						<input type="radio" name="sex" value="2" title="女" {if $info['sex']==2 }checked{/if}>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">生日</label>
					<div class="layui-input-inline">
						<input name="birthday"  value="{$info.birthday}" placeholder="请输入生日" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-inline">
						<input name="email" id="email" value="{$info.email}" placeholder="请输入邮箱" autocomplete="off" class="layui-input" type="email">
					</div>
					<div class="layui-form-mid" style="color: #999;">请填写正确的邮箱格式</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">国籍</label>
					<div class="layui-input-inline">
						<input name="guoji" value="{$info.guoji}" placeholder="请输入国籍" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">省份</label>
					<div class="layui-input-inline">
						<input name="province" value="{$info.province}" placeholder="请输入省份" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">城市</label>
					<div class="layui-input-inline">
						<input name="city" value="{$info.city}" placeholder="请输入城市" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">地址</label>
					<div class="layui-input-inline">
						<input name="addres" value="{$info.addres}" placeholder="请输入地址" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">业务员</label>
					<div class="layui-input-inline">
						<select name="tj_emp" lay-filter="aihao">
							{volist name="$ywy" id="v"} 
							<option value="{$v.id}" {if condition="$info.tj_emp eq $v.id" }selected{/if}>{$v.user_name}</option>
							{/volist}
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">余额</label>
					<div class="layui-input-inline">
						<input placeholder="请输入余额" value="￥{$info.balance}" autocomplete="off" class="layui-input" type="text" disabled>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">充值</label>
					<div class="layui-input-inline">
						<input name="balance" placeholder="请输入充值金额" autocomplete="off" class="layui-input" type="text">
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="btn">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
                <input type="hidden" name="id" value="{$info.id}">
			</form>

			<script src="__PUBLIC__/layui/layui.js"></script>
			<script src="__PUBLIC__/jquery/jquery.min.js"></script> 
			<script>
				layui.use(['layer', 'form'], function() {
					var layer = layui.layer,
						$ = layui.jquery,
						form = layui.form;
					$(window).on('load', function() {
						form.on('submit(btn)', function(data) { 
							var password = $('#password').val(); 
							var myemail = $('#email').val();
							var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
							var phone = $("#mobile").val(); 
							var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则 
							if(!reg.test(phone)) {
								layer.msg('手机号码格式不正确'); 
								return;
							}
							
							if(password){
								if(password.trim() == '') {
									layer.msg('密码不能为空');
									return false;
							    } 
								if($('#password').val().length < 6){
									layer.msg('密码不能小于6位数');
									return false;
								}
							}
							if(myemail){
								if(!myReg.test(myemail)){
							　　　　   	layer.msg('邮箱格式不对!');
									return false;
							　　  }
							}
							
							$.ajax({
								url: "{:url('admin/member/memedit')}",
								data: $('#mem').serialize(),
								type: 'post',
								async: false,
								success: function(res) { 
								    if(res.code == 1) {
			                              layer.msg(res.msg, function(index){
			                                location.href = res.url;
			                              })
			                        } else {
			                              layer.msg(res.msg);
			                        }
								}
							})
							return false;
						});
					});
				});
				
				function faedit(uid){
					var url = "{:url('member/faedit')}?uid=" + uid;
					layer.open({
					  type: 2,
					  title: '房券编辑',
					  shadeClose: true, 
					  area: ['550px', '500px'],
					  content: [url]
					}); 
				}
			</script>
		</div>
	</body>

</html>